<template>
	<view>
		<u-modal :show="show" ref="uModal" @cancel="$emit('close')" :closeOnClickOverlay="true"
			:showConfirmButton="false" :showCancelButton="true">
			<view style="width: 100%;">
				<u-row customStyle="margin-bottom: 10px" justify="space-between" size="mini" gutter="20">
					<u-col span="4">
						<u-button type="primary" :plain="!(item.isUp == 0)" text="上线" color="red"
							@click="toSetting('isUp',0)"></u-button>
					</u-col>
					<u-col span="4">
						<u-button type="primary" :plain="!(item.isUp == 1)" text="下线" color="red"
							@click="toSetting('isUp',1)"></u-button>
					</u-col>
					<u-col span="4">
						<u-button type="primary" :plain="!(item.isUp == 2)" text="成交" color="red"
							@click="toSetting('isUp',2)"></u-button>
					</u-col>
				</u-row>
				<u-row customStyle="margin-bottom: 10px" justify="space-between" size="mini" gutter="20">
					<u-col span="6">
						<u-button type="primary" :plain="!(item.recommend == 1)" text="开启自动匹配" color="red"
							@click="toSetting('recommend',1)"> </u-button>
					</u-col>
					<u-col span="6">
						<u-button type="primary" :plain="!(item.recommend == 0)" text="关闭自动匹配" color="red"
							@click="toSetting('recommend',0)"></u-button>
					</u-col>
				</u-row>
				<u-row customStyle="margin-bottom: 10px" justify="center" size="mini" gutter="20">
					<u-col span="12">
						<u-button type="primary" :plain="true" text="删除" color="red" @click="delConfirm"></u-button>
					</u-col>
				</u-row>

			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		jySettingTo,
		qzSettingTo,
		qgSettingTo,
		jyDel,
		qzDel,
		qgDel
	} from '@/api/api.js'
	import {
		RecruitUpdateApi,
		getJobUpdateApi,
		RecruitDeletesApi,
		JobDeletesApi
	} from '@/api/recruit.js'
	
	import {
		editSupple,
		editSuppleBeg,
		deleteSupple,
		deleteSuppleBeg
	} from "@/api/api.js"; //供应链
	import {
		ServiceUpdate,
		deleteService
	} from '@/api/service.js'
	import {
		editUnused,
		deleteUnused
	} from '@/api/unused.js' //二手

	export default {
		props: {
			show: {
				type: Boolean,
				default: false
			},
			item: {
				type: Object,
				default: () => {}
			}
		},
		data() {
			return {
				vipStatus : 0
			}
		},
		watch: {
			item(newVal) {
				console.log('newVal', newVal)
			}
		},
		methods: {
			async toSetting(key, val) {
				try{
					let params = {
						vipStatus: this.vipStatus,
						storeCategory: this.item.storeCategory,
						status: this.item.status,
						[key]: val
					}
					let res = null;
					if (this.item.id) {
						params.id = this.item.id
							
							
						if(this.item.vistype == 5){
							res = await RecruitUpdateApi(params)
						}else if(this.item.vistype == 10){
							res = await getJobUpdateApi(params)
						}else if(this.item.vistype == 11){
							res = await editSuppleBeg(params)
						}else if(this.item.vistype == 4){
							res = await editSupple(params)
						}else if(this.item.vistype == 2){
							res = await editUnused(params)
						}else if(this.item.vistype == 3){
							res = await ServiceUpdate(params)
						}else{
							res = await jySettingTo(params)
						}
						
					} else if (this.item.askrentId) {
						params.askrentId = this.item.askrentId
						res = await qzSettingTo(params)
					} else {
						params.buystoreId = this.item.buystoreId
						res = await qgSettingTo(params)
					}
					if (res.code == 200) {
						this.$emit('toChange',key,val)
						this.vipStatus = 0;
						this.$util.Tips({
							title:'操作成功'
						})
						this.$set(this.item,key,val)
					}else{
						console.log(res.message)
						this.$util.Tips({
							title:message
						})
					}
				}catch(e){
					console.log(e)
					this.$util.Tips({
						title:e
					})
				}
				
			},
			delConfirm() {
				let that = this;
				uni.showModal({
					title: "提示",
					content: '是否删除',
					success(res) {

						if (res.confirm) {
							that.delMeth()
						}
					}
				})
			},
			settingVip(val,key='isVip'){
				this.vipStatus = 1;
				this.toSetting(key,val);
			},
			async delMeth() {
				let res = null;
				if (this.item.id) {
					if(this.item.vistype == 5){
						res = await RecruitDeletesApi(this.item.id)
					}else if(this.item.vistype == 10){
						res = await JobDeletesApi(this.item.id)
					}else if(this.item.vistype == 4){
						res = await deleteSupple(this.item.id)
					}else if (this.item.vistype == 11){
						res = await deleteSuppleBeg(this.item.id)
					}else if (this.item.vistype == 2){
						res = await deleteUnused(this.item.id)
					}else if (this.item.vistype == 3){
						res = await deleteService(this.item.id)
					}else{
						res = await jyDel(this.item.id,this.item.storeCategory,this.item.status)
					}
					
				} else if (this.item.askrentId) {
					res = await qzDel(this.item.askrentId,this.item.storeCategory,this.item.status)
				} else {
					res = await qgDel(this.item.buystoreId,this.item.storeCategory,this.item.status)
				}
				if (res.code == 200) {
					console.log("shcnhu")
					this.$emit("opear", "删除成功",'del')
					this.$emit('close')
				}
			}
		}
	}
</script>

<style scoped lang="scss">

</style>